#!/bin/bash
source tools/getenv.sh

if [[ "$env" == "test" || "$env" == "prod" ]]; then
  if [[ ! -h $current_dir ]]; then
    echo -e "$BOLODRED $current_dir 不是软连，rollbackback命令仅支持软连$RESET"
    exit 1
  fi

  if [[ ! -h "${current_dir}.bak" ]]; then
    echo -e "$BOLODRED ${current_dir}.bak 目录不是软连,恢复不到rollback之前 $RESET"
    exit 1
  fi

  if [[ ! -e "${current_dir}.bak" ]]; then
    echo -e "$BOLODRED ${current_dir}.bak 目录不存在 $RESET"
    exit 1
  fi
  echo "rm -rf $current_dir"
  echo "mv ${current_dir}.bak $current_dir"
  rm -rf "$current_dir"
  mv "${current_dir}.bak" "$current_dir"

  echo -e "$GREEN 恢复完成$RESET"

  rollbackAfterRestart

else
  echo -e "$BOLD_WHITE $env 环境，不支持回滚 $RESET"
  exit 0
fi

echo "反向回滚完成"